﻿using LineTools;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(PolygonCollider2D))]
public class Shape2D : MonoBehaviour
{

    public Color LineColor;

    [HideInInspector]
    public List<Vector2> vertices = new List<Vector2>();

    [HideInInspector]
    public PolygonCollider2D colider;

    // Start is called before the first frame update
    void Start()
    {
        LineColor = Color.green;
        colider = this.GetComponent<PolygonCollider2D>();
    }

    // Update is called once per frame
    void Update()
    {

    }

     void UpdateShape()
    {
        vertices.Clear();
        Matrix4x4 matrix = this.transform.localToWorldMatrix;
        foreach (Vector2 point in colider.points)
        {
            vertices.Add(matrix.MultiplyPoint(point));
        }
    }

    public void DrawPolygon()
    {
        UpdateShape();
        LineTool.Instance().DrawPolygon(vertices, LineColor);
    }
}
